handler = {
	ALL = "##ALL##",
	
	new = function(owner)
		return {
			owner = owner,
			
			handlers = {},
			
			add = function(self, id, callback)
				assert(type(callback) == "function")
				assert(id ~= nil)
				local ha = self.handlers[id]
				if ha == nil then
					ha = {}
					self.handlers[id] = ha
				end
				ha[#ha + 1] = callback
			end,
			
			set = function(self, id, callback)
				assert(type(callback) == "function")
				assert(id ~= nil)
				self.handlers[id] = { callback }
			end,
			
			dispatch = function(self, id, ...)
				assert(id ~= nil)
				local function process(_id, ...)
					local ha = self.handlers[_id]
					if ha == nil then return end
					for i, h in pairs(ha) do
						if type(h) == "function"
							then h(self.owner, id, ...)
						end
					end
				end
				process(id, ...)
				process(handler.ALL, ...)
			end
		}
	end
}


